package com.xiaoxiangxueyuan.chapters01;

import java.util.Stack;

public class TwoStackImplementsQueue {

    public static Stack<Integer> dataStack = new Stack<>();
    public static Stack<Integer> tempStack = new Stack<>();

    public static void main(String[] args) {
        TwoStackImplementsQueue queue = new TwoStackImplementsQueue();
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        queue.offer(4);
        queue.offer(5);
        queue.offer(6);
        queue.offer(7);
        System.out.println("队列大小====="+queue.size());
        while (!queue.empty()){
            System.out.println(queue.poll());
        }
    }

    /**
     * 入队列
     * @param item
     */
    public void offer(Integer item){
        dataStack.push(item);
    }

    /**
     * 出队列
     */
    public Integer poll(){
        while (!dataStack.isEmpty()){
            tempStack.push(dataStack.pop());
        }
        Integer retVal = tempStack.pop();
        while (!tempStack.isEmpty()){
            dataStack.push(tempStack.pop());
        }
        return retVal;

    }

    public Integer size(){
        return dataStack.size();
    }

    public boolean empty(){
        return dataStack.isEmpty();
    }


}
